//
//  MineViewController.m
//  土巴兔
//
//  Created by 千锋 on 15/12/31.
//  Copyright (c) 2015年 IOS1503薛凯. All rights reserved.
//

#import "MineViewController.h"
#import "Default.h"
#import "MineFisrtTableViewCell.h"
#import "MineSecondTableViewCell.h"
#import "MineThirdTableViewCell.h"
#import "MineCarViewController.h"
#import "MineOrderViewController.h"
@interface MineViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (strong,nonatomic)NSArray* imageArr;
@property (strong,nonatomic)NSArray* textArr;
@end

@implementation MineViewController
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"我的";
 _imageArr=@[@"home_rili@2x.png",@"ico_gongdi_@2x.png",@"ico_zhuangxiudai_@2x.png",@"ico_dingdan_@2x.png",@"ico_gouwuche_@2x.png",@"ico_youhuiquan_@2x.png",@"ico_shoucang_@2x.png",@"ico_shezhi_@2x.png"];
    _textArr=@[@"日记",@"工地",@"装修贷",@"订单",@"购物车",@"优惠券",@"收藏",@"设置"];
    [self settableview];
}
- (void)settableview{
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.showsVerticalScrollIndicator=NO;
    _tableview.separatorInset=UIEdgeInsetsMake(0, 60, 0, 0);
    [_tableview registerNib:[UINib nibWithNibName:@"MineFisrtTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineFisrtTableViewCell"];
    [_tableview registerNib:[UINib nibWithNibName:@"MineSecondTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineSecondTableViewCell"];
    [_tableview registerNib:[UINib nibWithNibName:@"MineThirdTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineThirdTableViewCell"];
}
#pragma mark- 表格协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        MineFisrtTableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"MineFisrtTableViewCell"];
        [cell relayoutWithHeader:[[NSUserDefaults standardUserDefaults] objectForKey:@"iconurl"] andName:[[NSUserDefaults standardUserDefaults] objectForKey:@"username"] andCount:@"积分：20"];
        NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"iconurl"]);
        return cell;
    }else if (indexPath.row==1){
        MineSecondTableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"MineSecondTableViewCell"];
        return cell;
    }else{
        MineThirdTableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"MineThirdTableViewCell"];
        [cell relayoutWithImage:_imageArr[indexPath.row-2] andText:_textArr[indexPath.row-2]];
        return cell;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        return 140;
    }else{
        return 50;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==6) {
        MineCarViewController* carview=[[MineCarViewController alloc] init];
        [self presentViewController:carview animated:NO completion:nil];
    }else if (indexPath.row==5){
        MineOrderViewController* order=[[MineOrderViewController alloc] init];
        [self presentViewController:order animated:NO completion:nil];
    }
}
@end
